package com.laoye.mapper;

import com.laoye.bean.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface CartMapper {

    @Select("select * from cart where user_id=#{user_id}")
    List<Cart> getCart(@Param("user_id") Integer user_id);

    void addToCart(@Param("cart") Cart cart);

    @Delete("delete from cart where prod_id=#{prod_id} and user_id =#{user_id}")
    void deleteCart(@Param("prod_id") Integer prod_id, @Param("user_id") Integer user_id);

    @Update("update cart set count=count+1 ,money=money+prod_price where prod_id=#{prod_id} and user_id=#{user_id}")
    void increaseCount(@Param("prod_id") Integer prod_id, @Param("user_id") Integer user_id);

    @Update("update cart set count=count-1 ,money=money-prod_price where prod_id=#{prod_id} and user_id=#{user_id}")
    void decreaseCount(@Param("prod_id") Integer prod_id, @Param("user_id") Integer user_id);

    @Select("select count(*) from cart where user_id=#{user_id}")
    Integer getCount(@Param("user_id") Integer user_id);

    @Select("select count from cart where user_id= #{user_id} and prod_id= #{prod_id}")
    Integer getProductCount(@Param("user_id") Integer user_id, @Param("prod_id") Integer prod_id);

    @Update("update cart set count=count+#{count} where prod_id= #{prod_id} and user_id= #{user_id}")
    void updateCount(@Param("count") Integer count, @Param("prod_id") Integer prod_id, @Param("user_id") Integer user_id);

}
